package com.hiof.overlays;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.util.Log;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.hiof.R;
import com.hiof.data.MoraService;
import com.hiof.servercommunication.receive.beans.MeetingPointInfo;
import com.hiof.servercommunication.receive.beans.MemberLocationInfo;
import com.hiof.utility.LocationUtils;

import java.util.ArrayList;
import java.util.List;

public class MeetingPointsOverlay extends Overlay {
    Resources resources;
    Bitmap bmp;
    List<MeetingPointInfo> hotspots = new ArrayList<MeetingPointInfo>();

    public MeetingPointsOverlay(Resources resources) {
        this.resources = resources;
        hotspots = MoraService.getInstance().getMeetingPoints();
    }


    @Override
    public void draw(Canvas canvas, MapView mapView, boolean b) {
        super.draw(canvas, mapView, false);
        drawHotspots(canvas, mapView);
    }

    private void drawHotspots(Canvas canvas, MapView mapView) {
        int markerID = R.drawable.parking;
        Point screenPt = new Point();
        for (MeetingPointInfo meetingPointInfo : hotspots) {
            mapView.getProjection().toPixels(LocationUtils.getGoogleGeoPointsFromLocalGeoPoint((com.hiof.servercommunication.receive.beans.GeoPoint)meetingPointInfo.getGeoPoint()), screenPt);
            drawMarker(canvas, markerID, resources, screenPt.x, screenPt.y);
        }
    }

    public static void drawMarker(Canvas canvas, int id, Resources resources,
                                  int x, int y) {
        Bitmap bitmap = BitmapFactory.decodeResource(resources, id);
        canvas.drawBitmap(bitmap, x - 10, y - 10, null);
    }
}
